{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"color:#777777;background-color:#ffffff;font-size:12px;text-align:right;\">\n",
    "\tprepared by Abuzer Yakaryilmaz (QuSoft@Riga) | November 09, 2018\n",
    "</div>\n",
    "<table><tr><td><i> I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.</i></td></td></table>\n",
    "$ \\newcommand{\\bra}[1]{\\langle #1|} $\n",
    "$ \\newcommand{\\ket}[1]{|#1\\rangle} $\n",
    "$ \\newcommand{\\braket}[2]{\\langle #1|#2\\rangle} $\n",
    "$ \\newcommand{\\inner}[2]{\\langle #1,#2\\rangle} $\n",
    "$ \\newcommand{\\biginner}[2]{\\left\\langle #1,#2\\right\\rangle} $\n",
    "$ \\newcommand{\\mymatrix}[2]{\\left( \\begin{array}{#1} #2\\end{array} \\right)} $\n",
    "$ \\newcommand{\\myvector}[1]{\\mymatrix{c}{#1}} $\n",
    "$ \\newcommand{\\myrvector}[1]{\\mymatrix{r}{#1}} $\n",
    "$ \\newcommand{\\mypar}[1]{\\left( #1 \\right)} $\n",
    "$ \\newcommand{\\mybigpar}[1]{ \\Big( #1 \\Big)} $\n",
    "$ \\newcommand{\\sqrttwo}{\\frac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\dsqrttwo}{\\dfrac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\onehalf}{\\frac{1}{2}} $\n",
    "$ \\newcommand{\\donehalf}{\\dfrac{1}{2}} $\n",
    "$ \\newcommand{\\hadamard}{ \\mymatrix{rr}{ \\sqrttwo & \\sqrttwo \\\\ \\sqrttwo & -\\sqrttwo }} $\n",
    "$ \\newcommand{\\vzero}{\\myvector{1\\\\0}} $\n",
    "$ \\newcommand{\\vone}{\\myvector{0\\\\1}} $\n",
    "$ \\newcommand{\\vhadamardzero}{\\myvector{ \\sqrttwo \\\\  \\sqrttwo } } $\n",
    "$ \\newcommand{\\vhadamardone}{ \\myrvector{ \\sqrttwo \\\\ -\\sqrttwo } } $\n",
    "$ \\newcommand{\\myarray}[2]{ \\begin{array}{#1}#2\\end{array}} $\n",
    "$ \\newcommand{\\X}{ \\mymatrix{cc}{0 & 1 \\\\ 1 & 0}  } $\n",
    "$ \\newcommand{\\Z}{ \\mymatrix{rr}{1 & 0 \\\\ 0 & -1}  } $\n",
    "$ \\newcommand{\\Htwo}{ \\mymatrix{rrrr}{ \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} } } $\n",
    "$ \\newcommand{\\CNOT}{ \\mymatrix{cccc}{1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0} } $\n",
    "$ \\newcommand{\\norm}[1]{ \\left\\lVert #1 \\right\\rVert } $"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2> Python: Quick Reference </h2>\n",
    "<hr>\n",
    "<ul>\n",
    "    <li><a href=\"#Variables\">Variables</a></li>\n",
    "    <li><a href=\"#Arithmetic_operators\">Arithmetic operators</a></li>\n",
    "    <li><a href=\"#Objects\">Objects</a></li>\n",
    "    <li><a href=\"#Size_of_an_object\">Size of an object</a></li>    \n",
    "    <li><a href=\"#Loops\">Loops</a></li>\n",
    "    <li><a href=\"#Conditionals\">Conditionals</a></li>\n",
    "    <li><a href=\"#Logical_and_Boolean_operators\">Logical and Boolean operators</a></li>\n",
    "    <li><a href=\"#Double_list\">Double list</a></li>\n",
    "    <li><a href=\"#List_operations\">List operations</a></li>\n",
    "    <li><a href=\"#Functions\">Functions</a></li>\n",
    "    <li><a href=\"#Random_number\">Random number</a></li>\n",
    "</ul>\n",
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Variables\"></a>\n",
    "<h3> Variables </h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "number = 5 # integer\n",
    "real = -3.4 # float\n",
    "\n",
    "name = 'Asja' # string\n",
    "surname = \"Sarkana\" # string\n",
    "\n",
    "boolean1 = True # Boolean \n",
    "boolean1 = False # Boolean "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Arithmetic_operators\"></a>\n",
    "<h3> Arithmetic operators </h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Basic operators </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 13\n",
    "b = 5\n",
    "print(\"a =\",a)\n",
    "print(\"b =\",b)\n",
    "print()\n",
    "\n",
    "# basics operators\n",
    "print(\"a + b =\",a+b)\n",
    "print(\"a - b =\",a-b)\n",
    "print(\"a * b =\",a*b)\n",
    "print(\"a / b =\",a/b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Integer division and modulus operators </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 13\n",
    "b = 5\n",
    "print(\"a =\",a)\n",
    "print(\"b =\",b)\n",
    "print()\n",
    "\n",
    "# integer division\n",
    "print(\"a//b =\",a//b)\n",
    "\n",
    "# modulus operator\n",
    "print(\"a mod b =\",a % b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Exponent operator</h4>\n",
    "\n",
    "number\\*\\*exponent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = 5\n",
    "print(\"b =\",b)\n",
    "print()\n",
    "\n",
    "print(\"b*b =\",b**2)\n",
    "print(\"b*b*b =\",b**3)\n",
    "print(\"sqrt(b)=\",b**0.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Objects\"></a>\n",
    "<h3> Objects </h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Lists </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# list\n",
    "mylist = [10,8,6,4,2] \n",
    "\n",
    "print(mylist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Tuple </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tuple\n",
    "mytuple=(1,4,5,'Asja') \n",
    "\n",
    "print(mytuple)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Dictionary </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dictionary\n",
    "mydictionary = {\n",
    "    'name' : \"Asja\",\n",
    "    'surname':'Sarkane',\n",
    "    'age': 23\n",
    "}\n",
    "\n",
    "print(mydictionary)\n",
    "\n",
    "print(mydictionary['surname'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4>List of the other objects or variables </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# list of the other objects or variables\n",
    "list_of_other_objects =[\n",
    "    mylist,\n",
    "    mytuple,\n",
    "    3,\n",
    "    \"Asja\",\n",
    "    mydictionary\n",
    "]\n",
    "\n",
    "print(list_of_other_objects)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Size_of_an_object\"></a>\n",
    "<h3> Size of an object </h3>\n",
    "\n",
    "We use the method \"len()\" that takes an object as the input."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# length of a string\n",
    "print(len(\"Asja Sarkane\"))\n",
    "\n",
    "# size of a list\n",
    "print(len([1,2,3,4]))\n",
    "\n",
    "# size of a dictionary\n",
    "mydictionary = { 'name' : \"Asja\", 'surname':'Sarkane', 'age': 23}\n",
    "print(len(mydictionary))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Loops\"></a>\n",
    "<h3> Loops </h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> While-loop </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = 10\n",
    "while i>0: # while condition(s):\n",
    "    print(i)\n",
    "    i = i - 1   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> For-loop </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10): # i is in [0,1,...,9]\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(-5,6): # i is in [-5,-4,...,0,...,4,5]\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(0,23,4): # i is in [0,4,8,12,16,20]\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in [3,8,-5,11]: \n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in \"Sarkane\":\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dictionary\n",
    "mydictionary = {\n",
    "    'name' : \"Asja\",\n",
    "    'surname':'Sarkane',\n",
    "    'age': 23,\n",
    "}\n",
    "\n",
    "for key in mydictionary:\n",
    "    print(\"key is\",key,\"and its value is\",mydictionary[key])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Conditionals\"></a>\n",
    "<h3>Conditionals </h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for a in range(4,7):\n",
    "    \n",
    "    # if condition(s)\n",
    "    if a<5: \n",
    "        print(a,\"is less than 5\")\n",
    "        \n",
    "    # elif conditions(s)\n",
    "    elif a==5: \n",
    "        print(a,\"is equal to 5\")\n",
    "        \n",
    "    # else\n",
    "    else:\n",
    "        print(a,\"is greater than 5\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Logical_and_Boolean_operators\"></a>\n",
    "<h3>Logical and Boolean operators</h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Logical operator \"and\"</h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Logical operator \"and\"\n",
    "i = -3\n",
    "j = 4\n",
    "if i<0 and j > 0:  \n",
    "    print(i,\"is negative AND\",j,\"is positive\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4>Logical operator \"or\"</h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Logical operator \"or\"\n",
    "i = -2\n",
    "j = 2\n",
    "if i==2 or j == 2:  \n",
    "    print(\"i OR j is 2: (\",i,\",\",j,\")\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4>Logical operator \"not\" </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Logical operator \"not\"\n",
    "i = 3\n",
    "if not (i==2):\n",
    "    print(i,\"is NOT equal to 2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Operator \"equal to\" </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Operator \"equal to\"\n",
    "i = -1\n",
    "if i == -1:\n",
    "    print(i,\"is EQUAL TO -1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Operator \"not equal to\" </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Operator \"not equal to\"\n",
    "i = 4\n",
    "if i != 3:\n",
    "    print(i,\"is NOT EQUAL TO 3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Operator \"less than or equal to\" </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Operator \"not equal to\"\n",
    "i = 2\n",
    "if i <= 5:\n",
    "    print(i,\"is LESS THAN OR EQUAL TO 5\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Operator \"greater than or equal to\" </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Operator \"not equal to\"\n",
    "i = 5\n",
    "if i >= 1:\n",
    "    print(i,\"is GREATER THAN OR EQUAL TO 3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Double_list\"></a>\n",
    "<h3> Double list </h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "A =[\n",
    "    [1,2,3],\n",
    "    [-2,-4,-6],\n",
    "    [3,6,9]\n",
    "]\n",
    "\n",
    "# print all\n",
    "print(A)\n",
    "print()\n",
    "\n",
    "# print list by list\n",
    "for list in A:\n",
    "    print(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"List_operations\"></a>\n",
    "<h3>List operations</h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Concatenation of two lists </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = [1,2,3]\n",
    "list2 = [4,5,6]\n",
    "\n",
    "#concatenation of two lists\n",
    "\n",
    "list3 = list1 + list2\n",
    "print(list3)\n",
    "\n",
    "list4 = list2 + list1\n",
    "print(list4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Appending a new element </h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [0,1,2]\n",
    "\n",
    "list.append(3)\n",
    "print(list)\n",
    "\n",
    "list = list + [4]\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Functions\"></a>\n",
    "<h3>Functions</h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def summation_of_integers(n):\n",
    "    summation = 0\n",
    "    for integer in range(n+1):\n",
    "        summation = summation + integer\n",
    "    return summation\n",
    "\n",
    "print(summation_of_integers(10))\n",
    "print(summation_of_integers(20))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=\"Random_number\"></a>\n",
    "<h3>Random number</h3>\n",
    "\n",
    "We can use method \"randrange()\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from random import randrange\n",
    "\n",
    "print(randrange(10),\"is picked randomly between 0 and 9\")\n",
    "      \n",
    "print(randrange(-9,10),\"is picked randomly between -9 and 9\")\n",
    "\n",
    "print(randrange(0,20,3),\"is picked randomly from the list [0,3,6,9,12,15,18]\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
